#    One Room And A Goblin Invasion
#    Copyright (C) 2014  Jannik Haberbosch
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


# 3rd party modules
import pygame
pygame.init()

# Project modules
from code import doors_constants
from code import game_constants


class DoorHiding( pygame.sprite.Sprite ):
	"""A door hiding essentially is needed in order to cover the outer part of
	a door when it is closed so that the handle isn't visible, which otherwise,
	would look silly and wrong.
	Its' image is placed above a shut door.

	"""
	def __init__( self,
		dimensions,
		lefttop_position,
		angle ):
		"""
		Parameters
			dimensions
			tuple, list
			A tuple or list consisting of 2 items that define the width and height
			of the door hiding in pixel.
			
			lefttop_position
			tuple, list
			A tuple or list that defines the lefttop position of the image.
			
			angle
			integer
			Using the angle argument, the user can rotate the door hiding so it
			suits his/her uses.

		"""
		# Calling the parent constructor first.
		pygame.sprite.Sprite.__init__( self )

		self.dimensions = dimensions
		self.lefttop_position = lefttop_position
		self.angle = angle

		# Grab the colour information of the most right-bottom pixel to use
		# for hiding part of the door and the goblins before they enter the
		# room.
		window = pygame.display.get_surface()
		self.colour = window.get_at(
			doors_constants.BOTTOM_RIGHT_PIXEL
		)

		# Create the image and use the found color to fill it.
		self.image = pygame.Surface(
			self.dimensions
		)
		self.image.fill(
			self.colour
		)
		# White pixels will be transparent.
		self.image.set_colorkey(
			game_constants.WHITE
		)

		# Rotate the image.
		self.image = pygame.transform.rotate(
			self.image,
			self.angle
		)

		# And finally position the image by creating a pygame.Rect object.
		self.rect = self.image.get_rect(
			topleft = self.lefttop_position
		)
